<?php
/**
 * LilFloatBehaviorTest file
 */
App::import('Core', 'AppModel');
App::import('Behavior', 'LilFloat.LilFloat');

/**
 * LilFloatTestBehavior class
 *
 * @uses          LilFloatBehavior
 * @package       lil
 * @subpackage    lil.tests.cases.model.lil_float.test
 */
class LilFloatTestBehavior extends LilFloatBehavior {
}
/**
 * LilFloatModel class
 *
 * @uses          AppModel
 * @package       lil
 * @subpackage    lil.tests.cases.model.lil_float.test
 */
class LilFloatModel extends AppModel {
/**
* name property
*
* @var string
* @access public
*/
 	var $name = 'LilFloatModel';
}

/**
 * LilFloatBehaviorTest class
 *
 * @package       lil
 * @subpackage    lil.tests.cases.libs.model.lil_float
 */
class LilFloatBehaviorTest extends CakeTestCase {
/**
 * fixtures property
 *
 * @var array
 * @access public
 */
	var $fixtures = array(
		'plugin.lil_float.lil_float_model'
	);
/**
 * startCase method
 *
 * @access public
 * @return void
 */
	function startTest($method=null) {
		$this->LilFloatModel =& ClassRegistry::init('LilFloatModel');
	}
/**
 * endTest method
 *
 * @access public
 * @return void
 */
	function endTest($method) {
		unset($this->LilFloatModel);
		ClassRegistry::flush();
	}
/**
 * testBlogInstance method
 *
 * @access public
 * @return void
 */
	function testAreaInstance() {
		$this->assertTrue(is_a($this->LilFloatModel, 'LilFloatModel'));
	}
/**
 * testLilFloatBeforeSave method
 *
 * @access public
 * @return void
 */
	function testLilFloatBeforeSave() {
		Configure::write('LilFloat.decimalSeparator', ',');
		Configure::write('LilFloat.thousandsSeparator', ' ');
		
		$result = $this->LilFloatModel->Behaviors->attach('LilFloatTest', array());
		$result = $this->LilFloatModel->Behaviors->attached('LilFloatTest');
		$this->assertTrue($result);
		
		$data['LilFloatModel'] = array(
			'id'      => 1,
			'a_float' => '1 234,56'
		);
		$result = $this->LilFloatModel->save($data);
		if ($this->assertFalse(empty($result['LilFloatModel']['a_float']))) {
			$expected = 1234.56;
			$this->assertEqual($result['LilFloatModel']['a_float'], $expected);
		}
	}
/**
 * testLilFloatIsValidFloat method
 *
 * @access public
 * @return void
 */
	function testLilFloatIsValidFloat() {
		Configure::write('LilFloat.decimalSeparator', ',');
		Configure::write('LilFloat.thousandsSeparator', ' ');
		
		$result = $this->LilFloatModel->Behaviors->attach('LilFloatTest', array());
		$result = $this->LilFloatModel->Behaviors->attached('LilFloatTest');
		$this->assertTrue($result);
		
		$result = $this->LilFloatModel->isValidFloat(array('a_float' =>'2 123,31', 2));
		$this->assertTrue($result);
	}
}